//--------------------------------------------------
//公共变量
//--------------------------------------------------
var grid_height = ( Ext.getBody().getHeight()-10 );
var grid_width = (Ext.getBody().getWidth()-35)/3;


//--------------------------------------------------
//角色Grid
//--------------------------------------------------
var role_sm = new Ext.grid.CheckboxSelectionModel();
var role_grid = new Ext.grid.GridPanel({
    id:'role_grid',
    frame:true,
	height:grid_height,
	width:grid_width,
	tbar:[
		{text: '新增',listeners:{click:function(btn,e){ insertRole(); }}},
		'-',
		{text: '删除',listeners:{click:function(btn,e){ deleteRole(); }}}
	],
    store: new Ext.data.Store({
        reader: new Ext.data.JsonReader({
        	id:'id', 
        	fields:[ 
               {name: 'name'}, 
               {name: 'createtime'},
               {mame: 'orderby'}] 
        })
    }),
    sm: role_sm,
    colModel: new Ext.grid.ColumnModel({
        defaults: {
            width: 120,
            sortable: true
        },
        columns: [
        	new Ext.grid.RowNumberer({width:33}),
        	role_sm,
            {header: '角色名', dataIndex: 'name'},
            {header: '排序', dataIndex: 'orderby'},
            {header: '添加时间', dataIndex: 'createtime'}
        ]
    })
});


//--------------------------------------------------
//用户Grid
//--------------------------------------------------
var user_sm = new Ext.grid.CheckboxSelectionModel();
var user_grid = new Ext.grid.GridPanel({
	id:'user_grid',
	frame:true,
	height:grid_height,
	width:grid_width,
	tbar:[
		{text: '新增',listeners:{click:function(btn,e){ insertUser(); }}},
		'-',
		{text: '删除',listeners:{click:function(btn,e){ deleteUser(); }}}
	],
    store: new Ext.data.Store({
        reader: new Ext.data.JsonReader({
        	id:'id', 
        	fields:[ 
               {name: 'name'}, 
               {name: 'createtime'}] 
        })
    }),
    sm: user_sm,
    colModel: new Ext.grid.ColumnModel({
        defaults: {
            width: 120,
            sortable: true
        },
        columns: [
        	new Ext.grid.RowNumberer({width:33}),
        	user_sm,
            {header: '角色名', dataIndex: 'name'},
            {header: '添加时间', dataIndex: 'createtime'}
        ]
    })
});


//---------------------------------------------------
//角色_用户Grid
//点击角色表的一条记录，可以在此Grid显示该角色授予了哪些用户
//点击用户表的一条记录，可以在此Grid显示该用户授予了哪些权限    
//---------------------------------------------------
var role_user_grid = new Ext.grid.GridPanel({
	id:'role_user_grid',
	frame:true,
	height:grid_height,
	width:grid_width,
    store: new Ext.data.Store({
        reader: new Ext.data.JsonReader({
        	id:'id', 
        	fields:[ 
               {name: 'name'}
               ]
        })
    }),
    colModel: new Ext.grid.ColumnModel({
        defaults: {
            width: 120,
            sortable: true
        },
        columns: [
        	new Ext.grid.RowNumberer({width:33}),
            {header: '角色/用户', dataIndex: 'name'}
        ]
    })
});

//--------------------------------------------------
//布局容器
//--------------------------------------------------
var layout_container = new Ext.Panel({
	id:'layout_container',
	layout:'table',
	layoutConfig: {columns:3},
    border:false,
    items:[role_grid,user_grid,role_user_grid]
});

